﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t403Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t403_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t403Mgr mgr = new t403Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t403(e.Parameters[t403_Filter.ParamPrefix]));
            IList<t403> list = mgr.FindAllByPage_t403(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t403_Filter.ParamPrefix]);
            t403_MainStore.DataSource = list;
            t403_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t403Mgr mgr = new t403Mgr();
            RowSelectionModel sm = t403_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t403 _t403 = new t403();
                _t403.t403_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t403(_t403))
                {
                    log.Debug("t403中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t403_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t403Mgr mgr = new t403Mgr();
            t403 _t403 = new t403();
            if (Hid.Text.Length > 0)
                _t403 = mgr.FindById_t403(int.Parse(Hid.Text));
            
			_t403.t403_01 = Txtt403_01.Text.Trim();
			_t403.t403_02 = Txtt403_02.Text.Trim();
			_t403.t403_03 = Txtt403_03.Text.Trim();
			_t403.t403_04 = Txtt403_04.Text.Trim();
			_t403.t403_05 = Txtt403_05.Text.Trim();
			_t403.t403_06 = Txtt403_06.Text.Trim();
			_t403.t403_07 = Txtt403_07.Text.Trim();
			_t403.t403_08 = Txtt403_08.Text.Trim();
			_t403.t403_09 = Txtt403_09.Text.Trim();
			_t403.t403_10 = Txtt403_10.Text.Trim();
			_t403.t403_11 = Txtt403_11.Text.Trim();
			_t403.t403_12 = Txtt403_12.Text.Trim();
			_t403.t403_13 = Txtt403_13.Text.Trim();
			_t403.t403_14 = Txtt403_14.Text.Trim();
			_t403.t403_15 = Txtt403_15.Text.Trim();
			_t403.t403_16 = Txtt403_16.Text.Trim();
			_t403.t403_17 = Txtt403_17.Text.Trim();
			_t403.t403_18 = Txtt403_18.Text.Trim();
			_t403.t403_19 = Txtt403_19.Text.Trim();
			_t403.t403_20 = Txtt403_20.Text.Trim();
			_t403.t403_21 = Txtt403_21.Text.Trim();
			_t403.t403_22 = Txtt403_22.Text.Trim();
			_t403.t403_23 = Txtt403_23.Text.Trim();
			_t403.t403_24 = Txtt403_24.Text.Trim();
			_t403.t403_25 = Txtt403_25.Text.Trim();
			_t403.t403_26 = Txtt403_26.Text.Trim();
			_t403.t403_27 = Txtt403_27.Text.Trim();
			_t403.t403_28 = Txtt403_28.Text.Trim();
			_t403.t403_29 = Txtt403_29.Text.Trim();
			_t403.t403_30 = Txtt403_30.Text.Trim();
			_t403.t403_31 = Txtt403_31.Text.Trim();
			_t403.t403_32 = Txtt403_32.Text.Trim();
			_t403.t403_33 = Txtt403_33.Text.Trim();
			_t403.t403_34 = Txtt403_34.Text.Trim();
			_t403.t403_35 = Txtt403_35.Text.Trim();
			_t403.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t403(_t403);
            else
                isok = mgr.Add_t403(_t403);
            if (isok)
            {
                t403_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t403中执行了保存（插入或修改），并成功");
                t403_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}